//启示页面
import 'package:flutter/material.dart';

//列表页面示例
class SplashPage extends StatefulWidget {
//  MyListPage({Key key}) : super(key: key);

  final String title = "起始页面";

  @override
  _SplashPageState createState() => new _SplashPageState();
}

class _SplashPageState extends State<SplashPage> with TickerProviderStateMixin {
  Key key = GlobalKey();
  AnimationController controller; //动画控制器
  CurvedAnimation curved; //曲线动画，动画插值，
  bool forward = true;

  @override
  void initState() {
    //初始化，当当前widget被插入到树中时调用
    super.initState();
    controller = new AnimationController(
        vsync: this, duration: const Duration(seconds: 5));
    curved = new CurvedAnimation(
        parent: controller, curve: Curves.linear); // Curves.bounceOut 模仿小球自由落体运动轨迹
      curved.addStatusListener((state) {
        //当动画结束时执行动画反转
        if (state == AnimationStatus.completed) {
          // controller.reverse();
          //当动画在开始处停止再次从头开始执行动画
          // Navigator.of(context).pushNamed("/login");
          Navigator.pushReplacementNamed(context, "/login");
        } else if (state == AnimationStatus.dismissed) {
        }
      }); 

   controller.forward();//放在这里开启动画 ，打开页面就播放动画
  }

  @override
  Widget build(BuildContext context) {
//    print(G.navigatorKey.toString());
// child: FadeTransition(
//           opacity: animationTest,
//           child: Image.network(
//             'https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1582026997593&di=996b86c850e9edec1c3d04ec6ff41183&imgtype=0&src=http%3A%2F%2Fb-ssl.duitang.com%2Fuploads%2Fitem%2F201601%2F30%2F20160130164342_AtuPy.thumb.700_0.jpeg',
//           ),
//         ),

    final size = MediaQuery.of(context).size;
    final width = size.width;
    final height = size.height;

    return new Scaffold(
      body: new FadeTransition(
        //透明度动画
        opacity: curved, //将动画传入不同的动画widget
        child: Container(
          width: width,
          height: height,
          child: Image.network(
            'https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1582026997593&di=996b86c850e9edec1c3d04ec6ff41183&imgtype=0&src=http%3A%2F%2Fb-ssl.duitang.com%2Fuploads%2Fitem%2F201601%2F30%2F20160130164342_AtuPy.thumb.700_0.jpeg',
            fit: BoxFit.cover,
          ),
        ), //内部开始使用基本组件类型
      ),
    );
  }
}
